﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore;
using Sitecore.Resources;
using Sitecore.Shell.Applications.WebEdit.Commands;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Text;
using Sitecore.Web.UI.Sheer;

namespace ColorBox4Sitecore.Webedit
{
    public class WebeditColorboxLink : WebEditCommand
    {
        // Methods
        public override void Execute(CommandContext context)
        {
            Context.ClientPage.Start(this, "Run", context.Parameters);
        }

        protected static void Run(ClientPipelineArgs args)
        {
            if (args.IsPostBack)
            {
                if (args.HasResult)
                {
                    SheerResponse.Eval("window.parent.Sitecore.PageModes.ChromeManager.handleMessage('chrome:field:colorboxlinkinserted',{{colorboxClass:{0}}})", new object[] { args.Result });
                }
            }
            else
            {
                UrlString str = ResourceUri.Parse("control:RichText.ColorboxLink").ToUrlString();
                str.Add("mo", "webedit");
                str.Add("la", args.Parameters["language"]);
                SheerResponse.ShowModalDialog(str.ToString(), true);
                args.WaitForPostBack();
            }
        }
    }

}
